<div id="required_fields_message"><?php echo $this->lang->line('common_fields_required_message'); ?></div>
<ul id="error_message_box"></ul>
<?php
echo form_open('materials/save/'.$material_info->material_id,array('id'=>'material_form'));
?>
<fieldset id="item_basic_info">
<legend><?php echo $this->lang->line("materials_basic_information"); ?></legend>


<?php 
if ($material_info->material_id == '') {
///////////// NEW
?>

<div class="field_row clearfix">
<?php echo form_label($this->lang->line('materials_type').':', 'type',array('class'=>'required wide')); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'type',
		'id'=>'type',
		'value'=>$material_info->type)
	);?>
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label($this->lang->line('materials_weight_per_unit').':', 'weight_per_unit',array('class'=>'required wide')); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'weight_per_unit',
		'id'=>'weight_per_unit',
		'value'=>$material_info->weight_per_unit)
	);?>
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label($this->lang->line('materials_price').':', 'price',array('class'=>'required wide')); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'price',
		'id'=>'price',
		'value'=>$material_info->price)
	);?>
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label($this->lang->line('materials_price_per_unit').':', 'price_per_unit',array('class'=>'required wide')); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'price_per_unit',
		'id'=>'price_per_unit',
		'value'=>$material_info->price_per_unit)
	);?>
	</div>
</div>

<?php 
} else {
//////////// EDIT
?>

<div class="field_row clearfix">
<?php echo form_label($this->lang->line('materials_type').':', 'type',array('class'=>'wide')); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'type',
		'id'=>'type',
		'value'=>$material_info->type,
		'readonly'=>'readonly')
	);?>
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label($this->lang->line('materials_weight_per_unit').':', 'weight_per_unit',array('class'=>'wide')); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'weight_per_unit',
		'id'=>'weight_per_unit',
		'value'=>$material_info->weight_per_unit,
		'readonly'=>'readonly')
	);?>
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label($this->lang->line('materials_price').':', 'price',array('class'=>'required wide')); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'price',
		'id'=>'price',
		'value'=>$material_info->price)
	);?>
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label($this->lang->line('materials_price_per_unit').':', 'price_per_unit',array('class'=>'required wide')); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'price_per_unit',
		'id'=>'price_per_unit',
		'value'=>$material_info->price_per_unit)
	);?>
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label($this->lang->line('materials_timestamp').':', 'timestamp',array('class'=>'wide')); ?>
	<div class='form_field'>
	<?php 
	echo form_input(array(
		'name'=>'timestamp',
		'id'=>'timestamp',
		'value'=>$material_info->timestamp,
		'readonly'=>'readonly')
	);?>
	</div>
</div>

<?php 
}
?>


<?php
echo form_submit(array(
	'name'=>'submit',
	'id'=>'submit',
	'value'=>$this->lang->line('common_submit'),
	'class'=>'submit_button float_right')
);
?>
</fieldset>
<?php
echo form_close();
?>
<script type='text/javascript'>

//validation and submit handling
$(document).ready(function()
{
	$('#material_form').validate({
		submitHandler:function(form)
		{
			$(form).ajaxSubmit({
			success:function(response)
			{
				tb_remove();
				post_material_form_submit(response);
			},
			dataType:'json'
		});

		},
		errorLabelContainer: "#error_message_box",
 		wrapper: "li",
		rules:
		{
			type:"required",
			weight_per_unit:
			{
				required:true,
				number:true
			},
			price:
			{
				required:true,
				number:true
			},
			price_per_unit:
			{
				required:true,
				number:true
			}
   		},
		messages:
		{
			type:"<?php echo $this->lang->line('materials_type_required'); ?>",
			weight_per_unit:
			{
				required:"<?php echo $this->lang->line('materials_weight_per_unit_required'); ?>",
				number:"<?php echo $this->lang->line('materials_weight_per_unit_number'); ?>"
			},
			price:
			{
				required:"<?php echo $this->lang->line('materials_price_required'); ?>",
				number:"<?php echo $this->lang->line('materials_price_number'); ?>"
			},
			price_per_unit:
			{
				required:"<?php echo $this->lang->line('materials_price_per_unit_required'); ?>",
				number:"<?php echo $this->lang->line('materials_price_per_unit_number'); ?>"
			}

		}
	});
});
</script>